package com.panshi.controller.information;

import com.panshi.DiscussPage.PageBeanVo;
import com.panshi.api.IDiscussApi;
import com.panshi.po.DiscussPO;
import com.panshi.po.SeekPO;
import com.panshi.po.SortPO;
import com.panshi.vo.PageModel;
import com.panshi.vo.QueryDimVO;
import com.panshi.vo.SeekQueryDimVO;
import com.panshi.vo.UpdateDiscussVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Controller
@Slf4j
@RequestMapping("/discuss")
public class ZXDiscussController {

    @Resource
    private IDiscussApi iDiscussApi;

    @GetMapping("/query")
    public String queryPage(){

        return "information/zxdiscuss/discuss-query";
    }

    @PostMapping("/query")
    @ResponseBody
    public PageModel<DiscussPO> query(PageModel<DiscussPO> pm){
        pm.init();
        PageBeanVo pageBeanVo = new PageBeanVo();
        pageBeanVo.setCurrentPage(pm.getCurrentPage());
        pageBeanVo.setPageSize(pm.getPageSize());
        List<DiscussPO> list = iDiscussApi.queryDiscussPostBody(pageBeanVo).getData();
        log.info("资讯评论query ----------------list{}",list);
        pm.setList(list);
        Integer count = iDiscussApi.queryNumber().getData();
        pm.setCount(count);

        return pm;
    }

    @PostMapping("/query-vague/{vague}")
    @ResponseBody
    public PageModel<DiscussPO> queryVague(PageModel<DiscussPO> pm, @PathVariable String vague){
        pm.init();
        log.info("pm ------------------------{}",pm);

        QueryDimVO queryDimVO = new QueryDimVO();
        queryDimVO.setContent(vague);
        queryDimVO.setCurrentPage(pm.getCurrentPage());
        queryDimVO.setPageSize(pm.getPageSize());

        List<DiscussPO> sortPOList = iDiscussApi.queryDimDiscussPostBody(queryDimVO).getData();
        pm.setList(sortPOList);

        Integer count = iDiscussApi.queryDimNumber(vague).getData();
        pm.setCount(count);

        return pm;
    }

    //根据id获取评论，只能对该评论进行启用、禁用操作，不能做其他修改
    @PostMapping("/del")
    @ResponseBody
    public PageModel<DiscussPO> del(UpdateDiscussVO updateDiscussVO){
        PageModel<DiscussPO> pageModel = new PageModel<>();
        updateDiscussVO.setUpdatedate(new Date());
        log.info("updateDiscussVO ------------------------{}",updateDiscussVO);
        Integer status = iDiscussApi.updateDiscussPostBody(updateDiscussVO).getData();

        log.info("status ------------------------{}",status);

        if(status == 0){
            pageModel.setCode(9999);
            pageModel.setMsg("删除失败");
        }else if(status == 1){
            pageModel.setCode(10000);
            pageModel.setMsg("删除成功");
        }
        //SeekPO seekPO = iSeekApi.query

        return pageModel;
    }

}
